package com.qingcloud.adminbackend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qingcloud.adminbackend.entity.equipment.*;
import com.qingcloud.adminbackend.entity.equipment.*;
import com.qingcloud.adminbackend.entity.monitordata.MonitorDataBO;
import com.qingcloud.adminbackend.entity.monitordata.MonitorDataDTO;
import com.qingcloud.adminbackend.entity.sysstation.EquipmentSyncDTO;
import com.qingcloud.adminbackend.entity.sysstation.StationMiniInfo;
import com.qingcloud.adminbackend.entity.weatherdata.WeatherBO;
import com.qingcloud.adminbackend.entity.weatherdata.WeatherDTO;
import com.qingcloud.adminbackend.entity.weatherdata.WeatherExportBO;
import com.qingcloud.adminbackend.pojo.equipment.EquipmentDecoder;
import org.apache.ibatis.annotations.Param;

import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 设备表基本信息表 Mapper 接口
 * </p>
 *
 * @author luozehua
 * @since 2018-11-19
 */
public interface SysEquipmentMapper extends BaseMapper<SysEquipment> {

    /**
     * 设备绑定的站点
     *
     * @param equipmentDTO
     * @return
     */
    List<EquipmentBO> findStationEquipment(@Param("equipmentDTO") EquipmentDTO equipmentDTO);

    /**
     * 设备池
     *
     * @param equipmentListBO
     * @return
     */
    List<EquipmentListDTO> equipmentPool(@Param("equipmentListBO") EquipmentListBO equipmentListBO);

    /**
     * 批量添加设备
     *
     * @param sysEquipments
     */
    int insertEquipments(@Param("sysEquipments") List<SysEquipment> sysEquipments);

    /**
     * 修改设备状态
     *
     * @param equipmentId
     * @param status
     */
    void updateEquipmentByEquipmentId(@Param("equipmentId") String equipmentId, @Param("status") Integer status);

    /**
     * 查询设备是否已经存在
     *
     * @param ids
     * @return
     */
    List<String> findEquipments(@Param("ids") List<String> ids);

    /**
     * 分页查询相关所有的设备
     *
     * @param page
     * @param equipmentIds
     * @return
     */
    IPage<UnbindEquipmentDTO> findUnbindEquipment(Page<UnbindEquipmentDTO> page, @Param("equipmentIds") List<String> equipmentIds);

    /**
     * 修改设备种类
     *
     * @param ids
     */
    void updateEquipmentCatagory(@Param("equipmentCatagory") int equipmentCatagory, @Param("ids") List<String> ids);

    /**
     * 订单关联的设备
     *
     * @param equipmentListBO
     * @return
     */
    List<EquipmentListDTO> orderEquipment(@Param("equipmentListBO") EquipmentListBO equipmentListBO);

    /**
     * 设备池的设备列表Api
     *
     * @param equipmentPoolListBO
     * @return
     */
    IPage<EquipmentPoolListDTO> equipmentPoolList(Page<EquipmentPoolListDTO> page, @Param("equipmentPoolListBO") EquipmentPoolListBO equipmentPoolListBO);


    /**
     * 获取可用工作模式
     */
    String findEnableWorkMode(@Param("equipmentId") String equipmentId);

    /**
     * 检测设备是否在线
     */
    Boolean checkOnlineStatus(@Param("equipmentId") String equipmentId);

    /**
     * 设备详情
     *
     * @param equipmentId
     * @return
     */
    SysEquipmentDetailsDTO equipmentDetails(@Param("equipmentId") String equipmentId);

    Integer logicDelete(@Param("eId") String eId);

    Integer updateStatus(@Param("equipmentIds") List<String> equipmentIds,
                         @Param("status") Integer status,
                         @Param("userId") String userId,
                         @Param("date") String date);

    Integer updateVerifyStatus(@Param("equipmentIds") List<String> equipmentIds,
                               @Param("userId") String userId,
                               @Param("date") String date);

    List<Integer> findEquipmentProtocol(@Param("equipmentIds") List<String> equipmentIds);

    Integer updateIp(@Param("equipmentIds") List<String> equipmentIds, @Param("ipAdress") String ipAdress);


    /**
     * 条件查询设备信息
     *
     * @param equipmentListPara
     * @param userId
     * @return
     */
    IPage<EquipmentListDTO> equipmentList(IPage<EquipmentListDTO> page, @Param("equipmentListPara") EquipmentListPara equipmentListPara, @Param("userId") String userId);

    /**
     * 条件查询设备信息（超级管理员与完全管理权限用户）
     *
     * @param equipmentListPara
     * @return
     */
    IPage<EquipmentListDTO> equipmentMgrList(IPage<EquipmentListDTO> page, @Param("equipmentListPara") EquipmentListPara equipmentListPara);

    /**
     * 设备生产状态分页查询
     */
    IPage<ProductionStateVO> findProductionStatePage(Page<ProductionStateDTO> page,
                                                     @Param("dto") ProductionStateDTO dto);

    /**
     * 更新设备生产状态
     */
    Integer updateStandardFlag(@Param("standardFlag") Integer standardFlag,
                               @Param("equipmentIdList") List<String> equipmentIdList);

    /**
     * 已删除的设备
     *
     * @return
     */
    List<String> findStationIsDelete(@Param("equipmentIds") List<String> equipmentIds);

    StationMiniInfo getEqBind(@Param("equipmentId") String equipmentId);

    /**
     * 删除设备
     *
     * @param sysEquipments
     */
    void deleteEquipments(@Param("sysEquipments") List<SysEquipment> sysEquipments);

    /**
     * 查询设备对应的可用监测因子
     *
     * @param equpmentIds
     * @return
     */
    List<EquipmentListDTO> findFactorByEqupmentId(@Param("equpmentIds") List<String> equpmentIds);


    /**
     * 获取在线设备编号列表
     */
    List<String> findOnlineEquipmentIds();

    /**
     * 获取室内设备编号列表
     */
    List<String> findAitechEquipmentIds();

    /**
     * 查询设备
     *
     * @param weatherBO
     * @return
     */
    List<WeatherDTO> getWeatherData(@Param("weatherBO") WeatherBO weatherBO, @Param("equipmentIds") List<String> equipmentIds);

    /**
     * 有权访问的设备编号
     *
     * @param isAdmin
     * @param userId
     * @param orderIds
     * @param orgIds
     * @return
     */
    List<ModelDTO> getEquipmentIds(@Param("isAdmin") boolean isAdmin, @Param("userId") String userId,
                                   @Param("orderIds") List<String> orderIds, @Param("orgIds") List<String> orgIds);

    /**
     * 有权访问的设备编号
     *
     * @param isAdmin
     * @param userId
     * @param orderIds
     * @param orgIds
     * @return
     */
    Page<ModelDTO> getEquipmentIdsPage(Page<ModelDTO> page, @Param("isAdmin") boolean isAdmin, @Param("userId") String userId,
                                       @Param("orderIds") List<String> orderIds, @Param("orgIds") List<String> orgIds,
                                       String equipmentId, String productType);

    /**
     * 有权访问的设备编号
     *
     * @param isAdmin
     * @param userId
     * @param orderIds
     * @param orgIds
     * @return
     */
    List<ModelDTO> getEquipmentMgrIds(@Param("isAdmin") boolean isAdmin, @Param("userId") String userId,
                                      @Param("orderIds") List<String> orderIds, @Param("orgIds") List<String> orgIds);

    /**
     * 有权访问的设备编号
     *
     * @param isAdmin
     * @param userId
     * @param orderIds
     * @param orgIds
     * @return
     */
    Page<ModelDTO> getEquipmentMgrIdsPage(Page<ModelDTO> page, @Param("isAdmin") boolean isAdmin, @Param("userId") String userId,
                                          @Param("orderIds") List<String> orderIds, @Param("orgIds") List<String> orgIds,
                                          String equipmentId, String productType);

    /**
     * 设备池设备编号
     *
     * @return
     */
    List<ModelDTO> getEquipmentPoolIds();

    /**
     * 设备池设备编号
     *
     * @return
     */
    IPage<ModelDTO> getEquipmentPoolIdsPage(Page<ModelDTO> page, String equipmentId, String productType);

    /**
     * 超管查询所有设备
     *
     * @param orderIds
     * @param orgIds
     * @return
     */
    List<ModelDTO> getEquipmentAllIds(@Param("orderIds") List<String> orderIds, @Param("orgIds") List<String> orgIds);

    /**
     * 超管查询所有设备
     *
     * @param orderIds
     * @param orgIds
     * @return
     */
    IPage<ModelDTO> getEquipmentAllIdsPage(IPage<ModelDTO> page, @Param("orderIds") List<String> orderIds,
                                           @Param("orgIds") List<String> orgIds, String equipmentId, String productType);

    /**
     * 设备是否存在
     *
     * @param equipmentId
     * @return
     */
    Long existEquipment(@Param("equipmentId") String equipmentId);

    /**
     * 筛选范围内和设备池的设备
     *
     * @param orderIds
     * @param orgIds
     * @return
     */
    List<ModelDTO> getEquipmentAllModelIds(@Param("orderIds") List<String> orderIds, @Param("orgIds") List<String> orgIds);

    /**
     * 筛选范围内和设备池的设备
     *
     * @param orderIds
     * @param orgIds
     * @return
     */
    IPage<ModelDTO> getEquipmentAllModelIdsPage(IPage<ModelDTO> page, @Param("orderIds") List<String> orderIds,
                                                @Param("orgIds") List<String> orgIds, String equipmentId, String productType);

    /**
     * 原始数据内的设备设备
     *
     * @param weatherBO
     * @param equipmentIds
     * @return
     */
    List<WeatherDTO> getWeatherDataList(@Param("weatherBO") WeatherExportBO weatherBO, @Param("equipmentIds") List<String> equipmentIds);

    /**
     * 监测数据列表API
     *
     * @param monitorDataBO
     * @return
     */
    List<MonitorDataDTO> getMonitorData(@Param("monitorDataBO") MonitorDataBO monitorDataBO);

    /**
     * 数据导出
     *
     * @param equipmentListPara
     * @param userId
     * @return
     */
    List<EquipmentExportDTO> exportData(@Param("equipmentListPara") EquipmentListPara equipmentListPara, @Param("userId") String userId);


    /**
     * 查询站点下所有设备产品信息
     */
    List<EquipmentProduct> projectInfoByStationId(@Param("stationId") String stationId);

    /**
     * 根据设备id查询产品信息
     */
    EquipmentProduct projectInfoByEquipmentId(@Param("equipmentId") String equipmentId);

    /**
     * 按业务种类查询设备
     *
     * @param businessType
     */
    List<EquipmentSyncDTO> findEquipmentSyncInfo(@Param("businessType") Integer businessType);

    /**
     * 根据订单查询设备编号
     *
     * @param orderId      订单编号
     * @return
     */
    List<EquipmentProjectInfoDTO> findInfoByOrder(@Param("orderId") String orderId);

    /**
     * 根据设备编号查询信息
     */
    List<EquipmentProjectInfoDTO> findInfoByIds(@Param("equipmentIds") Collection<String> equipmentIds);

    /**
     * 按业务种类筛选编号
     * @param eidSet 设备编号集合
     * @param businessType 业务种类
     */
    Set<String> filterBusinessType(@Param("eidSet") Set<String> eidSet,
                                   @Param("businessType") Integer businessType);


    /**
     * 根据产品信号查询设备列表
     */
    List<String> selectEquipmentByProductType(@Param("productType") String productType);

    /**
     * 查询设备消息解码器
     */
    List<EquipmentDecoder> findMessageDecoders(@Param("equipmentId") String equipmentId);

}
